home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 175 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.6 KB  |  50 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: eddy@siemensrolm.com (eddy Gorsuch)
  3. Newsgroups: comp.std.c++
  4. Subject: Explicit constructor call vs Temporaries
  5. Date: 25 Jan 1996 16:12:06 GMT
  6. Organization: Siemens Rolm Communications Inc.
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4e6plv$idn@eclipse.eng.sc.rolm.com>
  9. NNTP-Posting-Host: taumet.eng.sun.com
  10. Content-Type: text
  11. Content-Length: 929
  12. X-Lines: 30
  13. Originator: clamage@taumet
  14.  
  15. Is an explicit call to an object constructor (an unamed object) const or
  16. not? I have code like the following where I don't care about the parameter
  17. to X::f(), so I just created an unamed T(). I thought I had tried to compile
  18. this code and got errors about trying to pass a const object to a non const
  19. reference parameter. Thinking that the unamed T() counts as a temporary (and
  20. therefor const) object, I believed that the compiler was right. Now somebody
  21. tells me that the following code is legal. Is it?
  22.  
  23. class T {
  24.   T();
  25.   ~T();
  26. }
  27.  
  28. class X {
  29.   X();
  30.   ~X();
  31.   f(T& t);
  32. }
  33.  
  34. int main() {
  35.   X x;
  36.   x.f(T());  // Compiler complained on this line
  37. }
  38.  
  39. eddy
  40. -- 
  41. ed.dy \'ed-e-\ n [ME (Sc dial.) ydy, prob. fr. ON itha; akin to OHG ith- 
  42.    again], L et and 1a: a current of water or air running contrary to the main 
  43.    current; esp)X : a small whirlpool 1b: a substance moving similarly  2: a 
  44.    contrary or circular current  - eddy vb
  45.  
  46. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  47.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  48.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  49.  
  50.